#####################################
### R Function: calibrate.ahn.lee ###
#####################################

calibrate.ahn.lee=function(x){
  
  options(warn=-1)
  
  repdata.cal=as.data.frame(matrix(data=NA,nrow=dim(raw.data)[1], ncol=dim(raw.data)[2]))
  colnames(repdata.cal)=colnames(x=raw.data)
  binary=c(0,1)
  data.names=colnames(raw.data)
  thresh.names=colnames(x)

  for(i in 1:ncol(raw.data)){
   if(is.element(el=data.names[i], set=thresh.names)==TRUE){
      repdata.cal[,i]=calibrate(x=raw.data[,i], type="fuzzy", threshold=c(x[1,data.names[i]], x[2,data.names[i]],x[3,data.names[i]]))
   } else if(is.element(el=data.names[i], set=thresh.names)==FALSE & sort(unique(raw.data[,i]))!=binary){
     thresholds=findTh(x=raw.data[,i], groups=4)
     repdata.cal[,i]=calibrate(x=raw.data[,i], type="fuzzy", thresholds=thresholds)
   } else{
     repdata.cal[,i]=raw.data[,i]
   } 
  }

  return(repdata.cal)

}
